package pri.zxx.datastructure.stack;

import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
import com.google.common.collect.ComparisonChain;
import com.google.common.collect.Ordering;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;

import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author TJ2020-6
 * @desc
 * @createTime 2020-06-15-16:16
 */
@Slf4j
public class GuavaDemo {

    @Test
    public void myTest() {
        Vector<Integer> integers = Stream.iterate(1, operand -> new Random().nextInt(500)).limit(10)
                .collect(Collectors.toCollection(Vector::new));
        boolean ordered = Ordering.natural().isOrdered(integers);
        log.warn("is Ordered:{}", ordered);
        List<Integer> orderedInt = Ordering.natural().sortedCopy(integers);
        log.warn("order:{}", orderedInt);
        Integer max = Collections.max(orderedInt);
        log.warn("max:{}", max);

        log.warn("----------------------------------------------------------------");

        Optional<Integer> integer = Optional.of(5);
        Integer orElse = integer.orElse(1);
        log.warn("orElse:{}", orElse);
        String txt = "this is a test msg";
        Preconditions.checkNotNull(txt, "something is wrong");
        log.warn("txt:{}", txt);

        int i = Objects.hashCode(txt);
        log.warn("hash:{}", i);

        int result = ComparisonChain.start().compare(2, 1).result();
        log.warn("result:{}", result);
    }
}
